package cn.easybuy.web.pre;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;

import cn.easybuy.dao.ProductCategoryDao;
import cn.easybuy.dao.impl.ProductCategoryDaoImpl;
import cn.easybuy.entity.Product;
import cn.easybuy.service.ProductService;
import cn.easybuy.service.impl.ProductServiceImpl;

public class ProductKindServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id3=request.getParameter("id3");
		String name3=request.getParameter("name3"); //对应的3级菜单名
		ProductCategoryDao pcd=new ProductCategoryDaoImpl(); 
		String name2=pcd.getParantNameById(Integer.parseInt(id3)); //对应的2级菜单名
		String name1=pcd.getGrandParantNameById(Integer.parseInt(id3)); //对应的1级菜单名
		ProductService ps=new ProductServiceImpl();
		HttpSession session=request.getSession();
		List<Product> productsList3=ps.getProductsByCategoryLevel3Id(Integer.parseInt(id3));//3级菜单下所有产品
		//需要图片，名称，价格，个数，对应的1 2 3级菜单名
		int number=productsList3.size();//3级菜单下产品个数
		request.setAttribute("number", number);
		request.setAttribute("name1", name1);
		request.setAttribute("name2", name2);
		request.setAttribute("name3", name3);
		request.setAttribute("productsList3", productsList3);
		request.getRequestDispatcher("BrandList.jsp").forward(request, response);
		
		/*	String productsList3JSON=JSON.toJSONString(productsList3);
		out.print(productsList3JSON);
		System.out.println(productsList3JSON);
		out.flush();
		out.close();*/
	}

}
